package com.engineering.elink.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.engineering.elink.co.BaseCo;
import com.engineering.elink.common.ErrorType;
import com.engineering.elink.common.Pagination;
import com.engineering.elink.dao.CatalogMapper;
import com.engineering.elink.dao.SubjectMapper;
import com.engineering.elink.domain.Subject;
import com.engineering.elink.service.SubjectService;
import com.engineering.elink.util.JSONUtil;

@Service
public class SubjectServiceImpl implements SubjectService {
	@Autowired
	private SubjectMapper subjectMapper;
	@Autowired
	private CatalogMapper catalogMapper;

	@Override
	public Map<String, Object> getList(BaseCo co) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", subjectMapper.selectList(co));
		map.put("Pagination", new Pagination(co, subjectMapper.selectCount(co)));
		return JSONUtil.getJSON(ErrorType.SUCCESS, map);
	}

	@Override
	public Map<String, Object> getInfo(String subjectId) {
//		Map<String, Object>map =new HashMap<String, Object>();
		return JSONUtil.getJSON(ErrorType.SUCCESS,catalogMapper.selectInfo(subjectId));
	}

	@Override
	public Map<String, Object> getBaseInfo(String subjectId) {
		// 更新专题的浏览量
		Subject subject = subjectMapper.selectByPrimaryKey(subjectId);
		subject.setVisitCount(subject.getVisitCount() + 1);
		subjectMapper.updateByPrimaryKeySelective(subject);

		return JSONUtil.getJSON(ErrorType.SUCCESS,subjectMapper.selectByPrimaryKey(subjectId));
	}
}
